package com.fxsh168.server.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.fxsh168.server.R;
import com.fxsh168.server.base.BaseActivity;
import com.fxsh168.server.entitys.PingJia;
import com.fxsh168.server.interfaces.Constant;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;


public class AboutUserActivity extends BaseActivity implements View.OnClickListener {
    ImageView imOne, imTwo, imThree, imFour, imFive;
    Button btnUp;
    EditText edSuggest;
    String comment_score = "1", comment_content, ids;
    ImageButton ib_re;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_driver);
        ids = getIntent().getStringExtra("ids");  //订单ID
        btnUp = (Button) findViewById(R.id.btnUp);
        edSuggest = (EditText) findViewById(R.id.edSuggest);
        imFive = (ImageView) findViewById(R.id.imFive);
        imFour = (ImageView) findViewById(R.id.imFour);
        imThree = (ImageView) findViewById(R.id.imThree);
        imTwo = (ImageView) findViewById(R.id.imTwo);
        imOne = (ImageView) findViewById(R.id.imOne);
        ib_re = (ImageButton) findViewById(R.id.ib_re);
        ib_re.setOnClickListener(this);
        imOne.setOnClickListener(this);
        imTwo.setOnClickListener(this);
        imThree.setOnClickListener(this);
        imFour.setOnClickListener(this);
        imFive.setOnClickListener(this);
        btnUp.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        imOne.setImageResource(R.mipmap.starwhite);
        imTwo.setImageResource(R.mipmap.starwhite);
        imThree.setImageResource(R.mipmap.starwhite);
        imFour.setImageResource(R.mipmap.starwhite);
        imFive.setImageResource(R.mipmap.starwhite);
        switch (v.getId()) {
            case R.id.ib_re:
                jumpActivity(MainActivity.class);
                break;
            case R.id.imOne:
                comment_score = "1";
                imOne.setImageResource(R.mipmap.starye);
                break;
            case R.id.imTwo:
                comment_score = "2";
                imOne.setImageResource(R.mipmap.starye);
                imTwo.setImageResource(R.mipmap.starye);
                break;
            case R.id.imThree:
                comment_score = "3";
                imOne.setImageResource(R.mipmap.starye);
                imTwo.setImageResource(R.mipmap.starye);
                imThree.setImageResource(R.mipmap.starye);
                break;
            case R.id.imFour:
                comment_score = "4";
                imOne.setImageResource(R.mipmap.starye);
                imTwo.setImageResource(R.mipmap.starye);
                imThree.setImageResource(R.mipmap.starye);
                imFour.setImageResource(R.mipmap.starye);
                break;
            case R.id.imFive:
                comment_score = "5";
                imOne.setImageResource(R.mipmap.starye);
                imTwo.setImageResource(R.mipmap.starye);
                imThree.setImageResource(R.mipmap.starye);
                imFour.setImageResource(R.mipmap.starye);
                imFive.setImageResource(R.mipmap.starye);
                break;
            case R.id.btnUp:
                comment_content = edSuggest.getText().toString().trim();
                sendPinJia();
                break;
        }
    }


    //    联网发送评价
    public void sendPinJia() {
        if (TextUtils.isEmpty(comment_score)) {
            comment_score = "5";
        }

        if (TextUtils.isEmpty(comment_content)) {
            comment_content = "";
        }

        OkHttpUtils.post().url(Constant.USERPINGJIA).addParams("id", ids).addParams("score_u", comment_score)
                .addParams("comment_u", comment_content).build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                Log.e("tag", "司机端发送的评价内容" + response);
                PingJia pingJia = new Gson().fromJson(response, PingJia.class);
                String code = pingJia.getCode();
                if (code.equals("200")) {
                    showToast("评价成功");
                    jumpActivity(MainActivity.class);
                    finish();
                }
            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        jumpActivity(MainActivity.class);
    }
}
